import { currentDates } from '../../utils/util'
const app = getApp()
Page({
  data: {
    silver: '../../assets/icons/silver.png',
    ordinary: '../../assets/icons/gold.png',
    gold: '../../assets/icons/gold.png',
    diamond: '../../assets/icons/diamond.png',
    statusBar: app.globalData.statusBar,
    customBar: app.globalData.customBar,
    custom: app.globalData.custom,
    scrollRate: 0,
    status: [
      { tit: '待付款', id: 0 },
      { tit: '待使用', id: 1 },
      { tit: '待评价', id: 2 },
      { tit: '已完成', id: 3 },
    ],
  },
  //我的权益
  _toMember() {
    wx.navigateTo({
      url: '/pages/member/member',
    })
  },

  // 个人资料
  _toInformation() {
    wx.navigateTo({
      url: '/pages/information/information',
    })
  },
  // 订单列表
  _toAppointment({
    currentTarget: {
      dataset: { id },
    },
  }) {
    wx.navigateTo({
      url: '/pages/appointment/appointment?status=' + (id == 0 ? 0 : id || -1),
    })
  },
  onShow() {
    this._getUser()
    this._getVip()
  },
  // 获取用户信息
  async _getUser() {
    let { code, data } = await wx.requestAsync({
      url: '/user/info',
    })
    if (code == 0) {
      this.setData(data)
      app.globalData.user = data
    }
  },
  //  会员信息
  async _getVip() {
    let { code, data } = await wx.requestAsync({
      url: '/user/vip/info',
    })
    if (code == 0) {
      if (data.reach_at) {
        data.reach_at = currentDates(data.reach_at * 1000, 1)
      } else {
        data.reach_at = '无'
      }
      this.setData(data)
    }
  },
})
